function [position_legend,rNormal,rBuy,rSell,nTrading,r_excess_after_cost] = testFLMA(price_path,risk_free,cost,short_MA_length,long_MA_length,band,option,day_minmax)
    rNormal = log(price_path(2:end)./price_path(1:end-1));
    day_lag = 3;
    price_path = price_path';
    short_MA_path = tsmovavg(price_path,option,short_MA_length);
    long_MA_path = tsmovavg(price_path,option,long_MA_length);

    rBuy = NaN(length(price_path),1);
    rSell = NaN(length(price_path),1);
    days = 0;
    flag = 0;
    buy = 0;
    sell = 0;
    nTrading = 0;
    flag_get_buy_stock = 0;
    flag_get_sell_stock = 0;
    
    %plot the result
    hold on
    h1 = plot(short_MA_path);
    h2 = plot(long_MA_path,'k');
    h3 = plot((1+band)*long_MA_path,'r');
    h4 = plot((1-band)*long_MA_path,'g');
    %axis([100 300 10 25])
    %grid on
    
    
    
    for i = short_MA_length:length(price_path) - day_lag
        if days == 0
            if short_MA_path(i) >= (1+band)*long_MA_path(i) && flag == 0
                days = days + 1;
                flag = 1;
                rBuy(i+day_lag) = log(price_path(i+day_lag)/price_path(i+day_lag-10))/10 - risk_free;
                buy = 1;
                if flag_get_buy_stock == 0
                    h7 = plot(i+day_lag,short_MA_path(i+day_lag),'s','MarkerEdgeColor','k',...
                        'MarkerFaceColor','m','MarkerSize',12);
                    flag_get_buy_stock = 1;               
                    flag_get_sell_stock = 0;
                    last_buy_day = i;
                end
            h5 = plot(i,short_MA_path(i),'o','MarkerEdgeColor','k',...
                 'MarkerFaceColor','r','MarkerSize',6);
            elseif short_MA_path(i) <= (1-band)*long_MA_path(i) && flag ==0
                days =days + 1;
                flag = 1;
                rSell(i+day_lag) = risk_free - log(price_path(i+day_lag)/price_path(i+day_lag-10))/10;
                sell = 1;
                if flag_get_sell_stock == 0 && flag_get_buy_stock == 1 && i-last_buy_day>=3
                    h8 = plot(i,short_MA_path(i),'s','MarkerEdgeColor','k',...
                        'MarkerFaceColor','c','MarkerSize',12);
                    flag_get_buy_stock = 0;
                    flag_get_sell_stock = 1;
                end
                h6 = plot(i,short_MA_path(i),'o','MarkerEdgeColor','k',...
                    'MarkerFaceColor','g','MarkerSize',6);
            end
        elseif days < 9 
            days = days + 1;
        elseif days == 9
            days = 0;
            flag = 0;
        end
        if buy == 1 && sell == 1
            h9 = plot(i,short_MA_path(i),'o','MarkerEdgeColor','k',...
                 'MarkerFaceColor','y','MarkerSize',7);
            nTrading = nTrading + 1;
            buy = 0;
            sell = 0;
        end
    end
    position_legend = [h1 h2 h3 h4 h5 h6 h7 h8 h9];
    r_excess = mean(rBuy(isnan(rBuy)==0)) + mean(rSell(isnan(rSell)==0));
    r_excess_after_cost = r_excess - cost*r_excess;
